package com.babycare.bbcareproduct.controller;

import com.babycare.bbcareproduct.entity.BrandEntity;
import com.babycare.bbcareproduct.service.BrandService;
import com.babycare.common.utils.PageUtils;
import com.babycare.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 品牌
 *
 * @author 一合行知（lyc）
 * @email icmilyc@163.com
 * @date 2024-04-07 11:23:56
 */
@RestController
@RequestMapping("product/brand")
@Api(tags = "品牌")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @ApiImplicitParam(name = "test",value = "测试参数",required = false)
    @ApiOperation(value = "查询所有商品")
    @GetMapping("/all")
    public R sayHi(@RequestParam(value = "test")String test){

        BrandEntity brandEntity = BrandEntity.builder().name("Banana").build();
        return R.ok().put("brand",brandEntity);
    }






    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("bbcareproduct:brand:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = brandService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    @RequiresPermissions("bbcareproduct:brand:info")
    public R info(@PathVariable("brandId") Long brandId) {
        BrandEntity brand = brandService.getById(brandId);

        return R.ok().put("brand", brand);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("bbcareproduct:brand:save")
    public R save(@RequestBody BrandEntity brand) {
        brandService.save(brand);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("bbcareproduct:brand:update")
    public R update(@RequestBody BrandEntity brand) {
        brandService.updateById(brand);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("bbcareproduct:brand:delete")
    public R delete(@RequestBody Long[] brandIds) {
        brandService.removeByIds(Arrays.asList(brandIds));

        return R.ok();
    }

}
